package com.woniuxy.microgoodsserver.auctionmag.controller;

import com.github.pagehelper.PageInfo;
import com.slsupermarket.common.res.ResponseMsg;
import com.woniuxy.microgoodsserver.auctionmag.service.GoodsBrandService;
import com.woniuxy.microgoodsserver.auctionmag.service.GoodsUnitService;
import com.woniuxy.microgoodsserver.bean.GoodsBrandBean;
import com.woniuxy.microgoodsserver.bean.GoodsUnitBean;
import com.woniuxy.microgoodsserver.bean.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/goodsUnit")
public class GoodsUnitController {

    @Resource
    GoodsUnitService goodsUintService;

    @RequestMapping(value = "/unitFindAllById",produces = {"application/json;charset=utf-8"})
    public GoodsUnitBean unitFindAllById(int id){
        System.out.println(id);
        GoodsUnitBean goodsUnitBean = goodsUintService.unitFindById(id);
        return goodsUnitBean;
    }

    @RequestMapping(value = "/unitFindAll",produces = {"application/json;charset=utf-8"})
    public PageInfo<GoodsUnitBean> brandFindAll(PageRequest pageRequest, GoodsUnitBean goodsUnitBean){
        System.out.println(pageRequest);
        System.out.println(goodsUnitBean);
        PageInfo<GoodsUnitBean> goodsUnitBeans = goodsUintService.unitFindAll(pageRequest,goodsUnitBean);
        System.out.println(goodsUnitBeans);
        return goodsUnitBeans;
    }

    @RequestMapping(value = "/saveBrand",produces = {"application/json;charset=utf-8"})
    public ResponseMsg saveBrand(GoodsUnitBean goodsUnitBean){
        int a = goodsUintService.savaUnit(goodsUnitBean);
        if (a<0){
            return ResponseMsg.builder().code(200).data(false).msg("成功").build();
        }
        return ResponseMsg.builder().code(200).data(true).msg("成功").build();
    }

    @RequestMapping(value = "/updateBrand",produces = {"application/json;charset=utf-8"})
    public ResponseMsg updateBrand(GoodsUnitBean goodsUnitBean){
        int a = goodsUintService.updateUnit(goodsUnitBean);
        if (a<0){
            return ResponseMsg.builder().code(200).data(false).msg("成功").build();
        }
        return ResponseMsg.builder().code(200).data(true).msg("成功").build();
    }
}
